//
//  XSquareTopView.swift
//  WeiBoReDo
//
//  Created by 放学跟鸽走 on 2017/4/16.
//  Copyright © 2017年 放学跟鸽走. All rights reserved.
//

import UIKit

class XSquareCellTopView: UIView {

    //头部间距
    lazy var headerMargin:UIView = UIView()
    /// 头像
    lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    
    /// 姓名
    lazy var nameLabel: UILabel = UILabel.cz_label(withText: "我的名字有点屌", fontSize: 15, color: UIColor.cz_color(withHex: 0xFC3E00))
    
    /// 会员图标
//    lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
    
    /// 时间
    lazy var timeLabel: UILabel = UILabel.cz_label(withText: "60秒前", fontSize: 10, color: UIColor.cz_color(withHex: 0xFF6C00))
    
    /// 来源
    lazy var sourceLabel: UILabel = UILabel.cz_label(withText: "来自火星", fontSize: 10, color: UIColor.cz_color(withHex: 0x828282))
    
    
    /// 认证标图
//    lazy var vipIconView: UIImageView = UIImageView(image:UIImage(named: "avatar_vip"))
    
    var viewModel:XSquareNewsViewModel?{
        didSet{
            
            //头像
            iconView.cz_setImage(urlString: viewModel?.squareNews?.head, placeholderImage: UIImage(named: "avatar_default_big"), isAvatar: true)
            nameLabel.text = viewModel?.squareNews?.tpName
            timeLabel.text = viewModel?.squareNews?.addtime
            sourceLabel.text = viewModel?.squareNews?.addFlag
            
        }
    }
    
    override init(frame:CGRect){
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
}
extension XSquareCellTopView{
    ///设置UI
    fileprivate func setupUI(){
        
        addSubview(headerMargin)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
//        addSubview(vipIconView)
//        addSubview(memberIconView)
        
        
        for v in subviews{
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        //Cell间距
        headerMargin.snp.makeConstraints { (make) in
            make.top.equalTo(snp.top)
            make.left.equalTo(snp.left)
            make.right.equalTo(snp.right)
            make.height.equalTo(StatusCellMargin)
        }
        //        headerMargin.backgroundColor = UIColor.cz_random()
        //图像
        iconView.snp.makeConstraints { (make) in
            make.top.equalTo(headerMargin.snp.bottom).offset(StatusCellMargin)
            make.left.equalTo(snp.left).offset(StatusCellMargin)
            make.width.equalTo(34)
            make.height.equalTo(34)
        }
        
        iconView.backgroundColor = UIColor.cz_random()
        //名字
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(iconView.snp.top)
            make.left.equalTo(iconView.snp.right).offset(StatusCellMargin)
            make.right.lessThanOrEqualTo(snp.right)
        }
        //会员图标
//        memberIconView.snp.makeConstraints { (make) in
//            make.centerY.equalTo(nameLabel.snp.centerY)
//            make.left.equalTo(nameLabel.snp.right).offset(4)
//        }
        
        //时间
        timeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconView.snp.right).offset(StatusCellMargin)
            make.bottom.equalTo(iconView.snp.bottom)
        }
        //来源
        sourceLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(timeLabel.snp.bottom)
            make.left.equalTo(timeLabel.snp.right).offset(StatusCellMargin)
        }
//        //认证图标
//        vipIconView.snp.makeConstraints { (make) in
//            make.bottom.equalTo(iconView.snp.bottom).offset(2)
//            make.right.equalTo(iconView.snp.right).offset(2)
//        }
        
        
        
    }
}
